public class BuyTicket implements  Runnable{
    int ticket=100;
    @Override
    public void run() {

        while (true){
            if (ticket<=0){
                break;
            }
            synchronized (this){
                System.out.println(Thread.currentThread().getName()+"卖出第"+ticket+"张票");
                ticket--;
            }


            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }
}
